package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.excel.ExcelReadVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.utils.ExcelFileUtil;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduAppointStudent.EduAppointStudentKeyVO;
import com.jwsoft.manager.common.vo.eduAppointStudent.EduAppointStudentQueryVO;
import com.jwsoft.manager.common.vo.eduAppointStudent.EduAppointStudentVO;
import com.jwsoft.manager.core.integration.EduAppointStudentIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * E类学籍名单维护表网关
 *
 * @author wangtao
 * @since 2022-12-15
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "E类学籍名单维护表", description = "E类学籍名单维护表")
public class EduAppointStudentController {

    @Autowired
    public EduAppointStudentIntegration eduAppointStudentIntegration;

    @Operation(summary = "E类学籍名单维护表分页查询",description = "E类学籍名单维护表分页查询")
    @PostMapping(value = "/eduAppointStudent0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduAppointStudentVO>> getList(@RequestBody @Validated EduAppointStudentQueryVO vo) {
        return AppResponse.successData(eduAppointStudentIntegration.getList(vo));
    }

    @Operation(summary = "E类学籍名单维护表根据主键查询详情",description = "E类学籍名单维护表根据主键查询详情")
    @PostMapping(value = "/eduAppointStudent0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAppointStudentVO> getById(@RequestBody @Validated EduAppointStudentKeyVO vo) {
        return AppResponse.successData(eduAppointStudentIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "E类学籍名单维护表新增",description = "E类学籍名单维护表新增")
    @PostMapping(value = "/eduAppointStudent0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAppointStudentVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduAppointStudentVO vo) {
        return AppResponse.successData(eduAppointStudentIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "E类学籍名单维护表修改",description = "E类学籍名单维护表修改")
    @PostMapping(value = "/eduAppointStudent0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAppointStudentVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduAppointStudentVO vo) {
        return AppResponse.successData(eduAppointStudentIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "E类学籍名单维护表删除",description = "E类学籍名单维护表删除")
    @PostMapping(value = "/eduAppointStudent0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduAppointStudentKeyVO vo) {
        eduAppointStudentIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "城区E类名单上传",description = "城区E类名单上传")
    @PostMapping(value = "/eduAppointStudent0007", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse<ExcelReadVO> readByCode(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            HttpServletResponse response) throws IOException {
        ExcelVO vo= ExcelFileUtil.getExcelVO(request,response,paramMap);

        EduAppointStudentVO eduAppointStudentVO = new EduAppointStudentVO();
        eduAppointStudentVO.setSchoolId(paramMap.get("schoolId").toString());
        MultipartFile file=ExcelFileUtil.getExcelFile(request);
        return AppResponse.successData(eduAppointStudentIntegration.readExcel(vo, file,eduAppointStudentVO));
    }






}
